import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);

//1.定义（路由）组件
import {Foo,Bar} from 'src/components/app/main.js';
import * as Cart from 'src/components/cart/main.js';
import NotFound from 'src/components/NotFound/NotFound';
const Form = r => {
    require(['src/components/form/form.vue'], r)
};
const Home = r => {
    require(['src/components/index/index.vue'], r)
};
const About = r => {
    require(['src/components/about/about.vue'], r)
};
const Info = r => {
    require(['src/components/info/info.vue'], r)
};
const Mine = r => {
    require(['src/components/mine/mine.vue'], r)
};

import {Assets,AssetsDetail} from 'src/components/assets/main.js';
/*import * as Info from 'src/components/info/main.js';*/
/*import * as About from 'src/components/about/main.js';*/
/*import * as Mine from 'src/components/mine/main.js';*/
import * as Toolbar from 'src/components/toolbar/main.js';
import App from 'src/components/app';
// 2. 定义路由
// 每个路由应该映射一个组件。 其中"component" 可以是
// 通过 Vue.extend() 创建的组件构造器，
// 或者，只是一个组件配置对象。
// 我们晚点再讨论嵌套路由。
const routes = [
 /* { path: '/',component: Assets.assets,name:'assets'},*/
  { path: '/foo', component: Foo },
  { path: '/bar', component: Bar },
  { path: '/cart', component: Cart.App },
  { path: '/form/:type', component:Form,name:'form',
  	beforeEnter: (to, from, next) => {
        if (localStorage.slug) {
              next({
                  path:'/mine/somting',
                  query: { redirect: to.fullPath } //这个我不知道是干啥的 字义上理解是重定向:当前url
              })
        } else {
          next();
        }
      }
  },//定义这个路由的name为form
  { path: '/home', component: Home,name:'home' },
  { path: '/assets', component: Assets,name:'assets' },
  { path: '/assetsdetail', component: AssetsDetail,name:'assets'}, 
  { path: '/info/:type', component: Info,name:'info' },
  { path: '/about/:type',component: About,name:'about' },
  { path: '/mine/:type',component: Mine,name:'mine' },
 /*  { path: '/mine', component: Mine.mine ,
     beforeEnter: (to, from, next) => {
          //用个人中心让你熟悉这个钩子函数
          if (localStorage.slug) {
              next();
          } else {
              next({
                  path:'/form/login',
                  query: { redirect: to.fullPath } //这个我不知道是干啥的 字义上理解是重定向:当前url
              })
          }
      }
  },*/
  { path: '/toolbar', component: Toolbar.toolbar,name:'toolbar' },
  { path: '*', component: NotFound }
]

// 3. 创建 router 实例，然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
export const router = new VueRouter({
  mode: 'history',
  routes // （缩写）相当于 routes: routes
})